package com.chris.homecare
{
	import flash.display.Bitmap;
	import flash.utils.Dictionary;
	
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;

	public class TextureAtlasManager
	{
		[Embed(source="/assets/sprites/spriteSheet.png")]
		public static const SpriteAtlasTexture:Class;
		
		[Embed(source="/assets/sprites/spriteSheet.xml", mimeType="application/octet-stream")]
		public static const SpriteAtlasXml:Class;
		
		private static var appTextures:Dictionary = new Dictionary();
		private static var appTextureAtlas:TextureAtlas;
		
		public static function getTexture(name:String):Texture
		{
			if (appTextures[name] == undefined)
			{
				var bitmap:Bitmap = new TextureAtlasManager[name]();
				appTextures[name]=Texture.fromBitmap(bitmap);
			}
			
			return appTextures[name];
		}
		
		public static function getAtlas():TextureAtlas
		{
			if (appTextureAtlas == null)
			{
				var texture:Texture = getTexture("SpriteAtlasTexture");
				var xml:XML = XML(new SpriteAtlasXml());
				appTextureAtlas=new TextureAtlas(texture, xml);
			}
			
			return appTextureAtlas;
		}
	}
}